/// ---------------------------------------------
///
/// 江懷玉
/// 
/// ---------------------------------------------
function LoadJs() {
    if (arguments.length == 0) {
         var _e = getPar1("entity");
         $.getScript('../Appjs/model.' + _e + '.js?r='+Math.random(), function () {

         });
         setTimeout(initC, 1000);
    }
    else {
        $.getScript(arguments[0], function () {
        });
    }
    getEntity();
    initC();
}

//function setControl() {
//    //    $('#ParentId').com({
//    //        url: '../AjaxData/Jsonlist.aspx?type=1&entity=Menus&condition=' + $.encodeURI("ParentId='00000000-0000-0000-0000-000000000000'") + '&order=MenuNo&r=' + Math.random(),
//    //        valueField: 'MenuId',
//    //        textField: 'Caption'
//    //    });
//    //var para = getPar1("para");   
//    //var obj = Decrypt(para);
//    var obj = eval("[" + Decrypt(getPar1("para")) + "]");
//    BaseOjbect.Handler(obj);
//}

var _editdata;
function initC() {
    //    if (typeof (InitEditControl) == "function") {
    //        setTimeout(InitEditControl, 20);  //初始化控件
    //    } 
    if (typeof(BaseObject)!="undefined") {
        //var obj = eval("[" + Decrypt(getPar1("para")) + "]");
        if (parent.data_Cache != null) {
            BaseObject.Handler(parent.data_Cache);
        }
        else {
            if (typeof (BaseObject.init) == "function") {
                BaseObject.init(parent.data_Cache);
            }
        }
        //获取后置空
        parent.data_Cache = null;
    }
    //setTimeout(getEntity, 200);
}

function getEntity() {
    var id = getPar1("id");
    if (id == '') {
        return;
    }
    var url = "../ajaxdata/GetEntity.aspx?entity=" + entity + "&id=" + id + "&r=" + Math.random();
    $.get(url, function (data, textstatus) {

        if (data != "[null]") {
            var reg = /[\r\n]/g;
            _editdata = eval(data.replace(reg, ""))[0];
            if (typeof (BaseObject) != "undefined") {

                if (_editdata != null) {
                    BaseObject.Handler(_editdata);
                }
                //获取后置空
                //parent.data_Cache = null;
            }
            $.JSONToForm($.toJSON(_editdata));
            if (typeof (InitHtmlControl) == "function") {
                setTimeout(InitHtmlControl, 20);  //初始化控件
                }
        }

    });
}

function InitEditControl() {
    //alert("Test");
}

function LoadListJs() {
    var _e = getPar1("entity");
    $.getScript('../Appjs/model.' + _e + '.list.js?r='+Math.random(), function () {
        setTimeout(intiListToolbar, 20);
    });
}

function intiListToolbar() {
    if (typeof (fnIntiListToolbar) == "function") {
        fnIntiListToolbar();
    }
}